/* 
 *  @module Pipe
 *  Author: Alex Hu
 *
 *  Example:
 *
 *
 */


'use strict';

GML.Pipe = (function(){
    
    var P = {};

    P.init = function(){
        // GML.Treasures["script"]["mine"]();
        //

        var that = P

        that.xhr = [];
        that["curNav"] = "";

        var i, item
            , RM = $("#rootMenu")
            , ownedMenu = $("<div />", {
                "class": "inner clear"
            })
            , rootURL = GML.URL.base
            , gmlURL = GML.URL
            , productURL = gmlURL.product
            , messageURL = gmlURL.message
            , buyineleadURL = gmlURL.buyinglead
            , subaccountURL = gmlURL.subaccount
            , printBtn = function(className, title, role){
                return '<a href="javascript:;" class="bg-icon ' + className + '" role="' + role + '">' + title + '</a>';
            }
            , switchMenu = printBtn("change-nav", T(205), "overall-Nav")
            , refreshMenu = printBtn("refurbish", T(206), "refresh-mailbox")
            /*
            , menu = {
                /* level 1 *./
                overall: {
                    className: "site-nav",
                    level: "1",
                    role: "overall-nav"
                },
                message: {
                    className: "site-nav nav-inquiry hide",
                    level: "1",
                    role: "message-mvo-nav"
                },
                buyinglead: {
                    className: "site-nav nav-buyinglead hide",
                    level: "1",
                    role: "buyinglead-mvo-nav"
                },

                /* level 2 *./
                myApp: {
                    title: T(180),
                    level: "2",
                    parentNode: "overall",
                    className: "my-apps"
                    // hierarchy: 00
                },
                allApp: {
                    title: T(185),
                    level: "2",
                    parentNode: "overall",
                    className: "level-nav"
                },
                startGuide: {
                    title: T(204),
                    level: "2",
                    parentNode: "overall"
                },
                messageMenu: {
                    title: switchMenu + refreshMenu,
                    level: "2",
                    parentNode: "message",
                    className: "my-apps"
                },
                message_category_menu: {
                    title: "",
                    level: "2",
                    parentNode: "message",
                    className: "level-nav"
                },
                buyingleadMenu: {
                    title: switchMenu + refreshMenu,
                    level: "2",
                    parentNode: "buyinglead",
                    className: "my-apps"
                },
                /*
                buyinglead_category_menu: {
                    title: "",
                    level: "2",
                    parentNode: "buyinglead",
                    className: "level-nav"
                },
                *./

                /* level 3 *./
                product: {
                    title: T(186),
                    level: "3",
                    parentNode: "allApp"
                },
                dataAnalysis: {
                    title: T(191),
                    level: "3",
                    parentNode: "allApp"
                },
                myBusiness: {
                    title: T(194),
                    level: "3",
                    parentNode: "allApp"
                },
                appCenter: {
                    title: T(197),
                    level: "3",
                    parentNode: "allApp"
                },
                subaccount: {
                    title: T(207),
                    level: "3",
                    parentNode: "allApp"
                },
                messageCategory: {
                    title: T(208),
                    level: "3",
                    parentNode: "message_category_menu"
                },

                /* level leaf *./
                MyGlobalMarket: {
                    title: T(181),
                    parentNode: "myApp",
                    level: "leaf",
                    className: "c-home",
                    URL: rootURL + "mygm/home/homepage/home.gm"
                },
                WebsiteEntrance: {
                    title: T(182),
                    parentNode: "myApp",
                    level: "leaf",
                    className: "c-room",
                    URL: ID.siteURL,
                    customAttr: [
                        { key: "target", value: "_blank" }
                    ]
                },
                ProductAddEntrance: {
                    title: T(183),
                    parentNode: "myApp",
                    level: "leaf",
                    className: "c-add-pro",
                    URL: rootURL + "mygm/product/product/enterEdit.gm?em=false"
                },
                CompanyEntrance: {
                    title: T(184),
                    level: "leaf",
                    parentNode: "myApp",
                    className: "c-company",
                    URL: rootURL + "mygm/companyprofile/companyprofile/basic.gm"
                },
                ProductManagementEntrance: {
                    title: T(187),
                    level: "leaf",
                    parentNode: "product",
                    className: "c-manager-pro",
                    URL: productURL + "manage.gm"
                },
                WebsiteManageEntrance: {
                    title: T(188),
                    level: "leaf",
                    parentNode: "product",
                    className: "c-sub-station",
                    URL: productURL + "enterCat.gm"
                },
                WebsiteNewProductSortEntrance: {
                    title: T(189),
                    level: "leaf",
                    parentNode: "product",
                    className: "c-rank-pro",
                    URL: productURL + "enterNewProd.gm"
                },
                ProductAuditRecord: {
                    title: T(190),
                    level: "leaf",
                    parentNode: "product",
                    className: "c-check",
                    URL: productURL + "enterRemind.gm"
                },
                operationStatistic: {
                    title: T(192),
                    level: "leaf",
                    parentNode: "dataAnalysis",
                    className: "c-opt-activity",
                    URL: rootURL + "mygm/effect/manueffect/viewOperationPage.gm"
                },
                businessOpportunity: {
                    title: T(193),
                    level: "leaf",
                    parentNode: "dataAnalysis",
                    className: "c-effect",
                    URL: rootURL + "mygm/effect/manueffect/viewEffectPage.gm"
                },
                messageCenter: {
                    title: T(195),
                    level: "leaf",
                    parentNode: "myBusiness",
                    className: "c-inquiry",
                    URL: messageURL + "inbox.gm"
                },
                manageBuyinglead: {
                    title: T(196),
                    level: "leaf",
                    parentNode: "myBusiness",
                    className: "c-buying-subscibe",
                    URL: buyineleadURL + "loadBuyingLeadList.gm"
                },
                GMCHistoryEntrance: {
                    title: T(198),
                    level: "leaf",
                    parentNode: "appCenter",
                    className: "c-gmc-report",
                    URL: rootURL + "mygm/gmccenter/mygmgmcreport/mListHistory.gm"
                },
                GMCView: {
                    title: T(199),
                    level: "leaf",
                    parentNode: "appCenter",
                    className: "c-gmc-ctf",
                    URL: rootURL + "mygm/gmccenter/mygmgmcreport/mViewBrief.gm"
                },
                EXHAddEntrance: {
                    title: T(200),
                    level: "leaf",
                    parentNode: "appCenter",
                    className: "c-add-exh",
                    URL: rootURL + "mygm/exhibition/exhibition/enterExhibitionAdd.gm"
                },
                EXHUpcomingListData: {
                    title: T(201),
                    level: "leaf",
                    parentNode: "appCenter",
                    className: "c-future-exh",
                    URL: rootURL + "mygm/exhibition/exhibition/enterExhibitionUpcoming.gm"
                },
                EXHHistory: {
                    title: T(202),
                    level: "leaf",
                    parentNode: "appCenter",
                    className: "c-old-exh",
                    URL: rootURL + "mygm/exhibition/exhibition/enterExhibitionPrevious.gm"
                },
                WebsiteTheme: {
                    title: T(203),
                    level: "leaf",
                    parentNode: "appCenter",
                    className: "c-theme",
                    URL: rootURL + "mygm/companyprofile/companyprofile/personalize.gm"
                },
                SuaccountAddEntrance: {
                    title: T(209),
                    level: "leaf",
                    parentNode: "subaccount",
                    className: "c-add-exh",
                    URL: subaccountURL + "add.gm"
                },
                SuaccountManageEntrance: {
                    title: T(210),
                    level: "leaf",
                    parentNode: "subaccount",
                    className: "c-future-exh",
                    URL: subaccountURL + "manage.gm"
                },
                LoginHistoryEntrance: {
                    title: T(211),
                    level: "leaf",
                    parentNode: "subaccount",
                    className: "c-add-exh",
                    URL: subaccountURL + "loginHistory.gm"
                },
                inquiryAssignment: {
                    title: T(212),
                    level: "leaf",
                    parentNode: "subaccount",
                    className: "c-add-exh",
                    URL: "/gmvo/accountsetting/loadPage.gm"
                },
                messageInbox: {
                    title: T(213) + ' <strong id="mvo_M_unreadMSG" class="num hide">()</strong>', // T(200),
                    level: "leaf",
                    parentNode: "messageMenu",
                    className: "",
                    URL: messageURL + "inbox.gm"
                },
                IMOutboxEntrance: {
                    title: T(214),
                    level: "leaf",
                    parentNode: "messageMenu",
                    className: "",
                    URL: messageURL + "outbox.gm"
                },
                IMTrashEntrance: {
                    title: T(215),
                    level: "leaf",
                    parentNode: "messageMenu",
                    className: "",
                    URL: messageURL + "trash.gm"
                },
                IMSafetyEntrance: {
                    title: T(221),
                    level: "leaf",
                    parentNode: "messageMenu",
                    className: "",
                    URL: messageURL + "safety.gm"
                },
                IMCompanyInquiryEntrance: {
                    title: T(216),
                    level: "leaf",
                    parentNode: "messageCategory",
                    className: "i-company",
                    URL: messageURL + "companyInquiry.gm"
                },
                IMProductInquiryEntrance: {
                    title: T(217),
                    level: "leaf",
                    parentNode: "messageCategory",
                    className: "i-product",
                    URL: messageURL + "productInquiry.gm"
                },
                IMBLReplyEntrance: {
                    title: T(218),
                    level: "leaf",
                    parentNode: "messageCategory",
                    className: "i-reply",
                    URL: messageURL + "buyingleadReply.gm"
                },
                myBuyinglead: {
                    title: T(219) + ' <strong id="mvo_BL_unreadMSG" class="num hide"></strong>', // T(200),
                    level: "leaf",
                    parentNode: "buyingleadMenu",
                    className: "",
                    URL: buyineleadURL + "loadMyBuyingLeadList.gm"
                },
                buyingleadReader: {
                    title: T(220),
                    level: "leaf",
                    parentNode: "buyingleadMenu",
                    className: "",
                    URL: buyineleadURL + "loadBuyingLeadList.gm"
                }
            }
            ;

        var printMenu = function(key){
            var node = menu[key];

            if(!node || node.entity){
                return;
            }

            var i, item, entity, _entity, role, icon
                , parent_node_key = node.parentNode
                , parentNode = menu[parent_node_key] || {}
                , parent_node_entity = parentNode.entity
                , customAttr = node.customAttr || []
                , className = node.className
                , compiled_custom_attr = ""
                ;

            if(!parent_node_key){
                parent_node_entity = ownedMenu;
            }

            if(!parent_node_entity){
                printMenu(parent_node_key);
                parent_node_entity = parentNode.entity;
            }

            for(i=0; i<customAttr.length; i++){
                item = customAttr[i];
                compiled_custom_attr += " " + item.key + "=" + item.value;
            }

            switch(node.level){
                case "1":
                    entity = '<div class="' + className + '" role="' + node.role + '"></div>';
                    entity = $(entity);
                    _entity = entity;
                    break;
                case "2":
                    entity = [
                        '<div class="nav-item">',
                            '<h3>' + node.title + '</h3>',
                            // '<h3><a href="javascript:;" class="bg-icon' + node.className + '"></a>' + node.title + '</h3>',
                            '<ul class="' + className + '"></ul>',
                        '</div>'
                    ].join("");
                    entity = $(entity);
                    _entity = entity.find("ul");
                    break;
                case "3":
                    entity = [
                    	'<li>',
                        	'<a class="level-top bg-icon tit-retracting" href="javascript:;">' + node.title + '</a>',
                            '<ul class="stage hide"></ul>',
                        '</li>',
                    ].join("");
                    entity = $(entity);
                    _entity = entity.find("ul");
                    break;
                case "leaf":
                    role = className === "c-room" ? "" : ' role="navItem"';
                    icon = className ? '<span class="bg-icon ' + className + '"></span>' : "" ;
                    entity = '<li><a href="' + node.URL + '"' + role + compiled_custom_attr + '>' + icon + node.title + '</a></li>';
                    entity = $(entity);
                    _entity = entity;
                    break;
            }

            node["entity"] = _entity;
            entity.appendTo(parent_node_entity);
        };
            */

        /*
        $.ajax({
            url: "/gmvo/mygm/common/auth/mvoMenu.gm",
            cache: false,
            /*
            beforeSend: function(){
            },
            *./
            success: function(d){
                if(d["status"] !== "success"){
                    RM.html(T(6));
                    return;
                }

                var auth = d["auths"];

                for(i=0; i<auth.length; i++){
                    item = auth[i].serCode;
                    GML.auth[item] = true;
                    switch(item){
                        case "StatOperationEntrance":
                            printMenu("operationStatistic");
                            printMenu("businessOpportunity");
                            break;
                        case "IMInboxEntrance":
                            printMenu("messageCenter");
                            printMenu("messageInbox");
                            break;
                        case "BLSubscriptionEntrance":
                            printMenu("manageBuyinglead");
                            printMenu("buyingleadReader");
                            printMenu("myBuyinglead");
                            break;
                        default:
                            printMenu(item);
                    }
                }

                RM.html(ownedMenu);
                */

        var map = []
            , navItem = $('#container > .extra').find('[role=navItem]')
            , theater = GML.RT
            , spinner = theater.siblings('.spinnerCenter')
            , $overallNav = $('.site-nav[role=overall-nav]')
            , $MsgMvoNav= $('.site-nav[role=message-mvo-nav]')
            , $BLMvoNav = $('.site-nav[role=buyinglead-mvo-nav]')
            , $MsgBvoNav = $('.site-nav[role=message-bvo-nav]')
            , $BLBvoNav = $('.site-nav[role=buyinglead-bvo-nav]')
            , $SEventBvo = $('.site-nav[role=sourcing-event-nav]')
            , curNav = {}
            , positionRT
            ;

        that.theater = theater;
        that.spinner = spinner;
        positionRT = theater.position();
        spinner.css({
            'width': theater.outerWidth(true),
            'left': positionRT.left,
            'top': positionRT.top
        });

        that.overallNav = $overallNav;
        that.MsgMvoNav = $MsgMvoNav;
        that.BLMvoNav = $BLMvoNav;
        that.MsgBvoNav = $MsgBvoNav;
        that.BLBvoNav = $BLBvoNav;
        that.SEventBvo = $SEventBvo;
        // that.reHide($navInquiry);
        // that.reHide($navBuylead);
        $(doc).on('click', '[role=overall-Nav]', function(e){
            GML.Pipe.swapNav('overall');
            e.preventDefault();
        });
        /*
        $('.change-nav', $('#container > .extra')).click(function(){
            GML.Pipe.swapNav('overall');
        });
        */
        curNav.name = 'overall'; 
        curNav.item = $(""); // $overallNav; // $("");
        curNav.overallW = $overallNav.outerWidth(true);
        that.curNav = curNav;

        // that.reHide(spinner);

        for(var i=0; i<navItem.length; i++){
            var $this = $(navItem[i])
                , nav = []
                ;
            // if($this.hasClass('level-kid')){
                nav.push($this.attr('href'));
                nav.push($this);
                map.push(nav);
                $this.parent().hover(
                    function(){
                        $(this).addClass('hover');
                    }
                    , function(){
                        $(this).removeClass('hover');
                    }
                );
            // }
            // that.packNav($this);
        }
        $(document).on('click', '[role=navItem]', function(e){
            var $this = $(this);
            if($this.closest('[role=panelMD]').length){
                GML.Mole.mask.data('shut')();
            }
            that.dig({ 'url': $this.attr('href'), 'navItem': $this });
            e.preventDefault();
        });
        that.map = map;

            that.renderNav();

        /* EOF Side Menu */

        window.onpopstate = function(event){
            if(event.state && !that.init){
                GML.RT.unbind('click');
                theater.html(event.state.cont);
                that.mapping(event.state.url);
                GML.Raider.hunt();
            }
        }

        setTimeout(function(){
            that.historyManage();
            that.init = true;
            GML.Raider.hunt();
        }, 100);
        /*
            }
        });
        */
    }

    P.packNav = function(element){
        var that = P
            , $this = element
            ;

        $this.click(function(e){
            that.dig({ 'url': $(this).attr('href'), 'navItem': $(this) });
            e.preventDefault();
        });
    }

    P.dig = function(parcel){
        var param = parcel.data ? parcel.data : {}
            , type = parcel.type ? parcel.type : 'get'
            , navItem = parcel.navItem ? parcel.navItem : $('')
            , that = P
            , url = parcel.url ? parcel.url : ''
            // , theater = that.theater
            , $RT = that.theater
            , spinner = that.spinner
            , RT_h, i, collect, collectDialog
            , xhr = that.xhr
            ;

        if(!url){
            $RT.html('The Wrong Request.');
            return false;
        }

        for(i=0; i<xhr.length; i++){
            xhr[i].abort();
        }
        that.xhr = [];

        param['pipe'] = 'ajax';
        that.xhrQ(
            $.ajax({
                url: url
                , type: type
                , data: param
                , beforeSend: function(){
                    GML.Spinner($RT);
                    // RT_h = $RT.height();
                    // $RT.css('minHeight', RT_h);
                    // spinner.height(RT_h);
                    // spinner.show();
                }
                , error: function(jqXHR){
                    if(jqXHR.status !== 0){
                        $RT.html('Sorry, I\'m afraid the page you requested doesn\'t exist.');
                    }
                    GML.Spinner($RT);
                }
                , success: function(data){
                    /* clear Event listener, panel triggerd by previous page */
                    $RT.unbind('click');
                    collect = $RT.data('collect');
                    if(collect){
                        for(i=0; i<collect.length; i++){
                            collect[i].remove();
                        }
                        $RT.data('collect', []);
                    }
                    collectDialog = $RT.data('collect-dialog');
                    if(collectDialog){
                        for(i=0; i<collectDialog.length; i++){
                            collectDialog[i].children('.ui-widget-content').dialog('destroy').remove();
                        }
                        $RT.data('collect-dialog', []);
                    }

                    if(!navItem.hasClass('cur')){
                        that.mapping(url);
                    }
                    GML.Spinner($RT);
                    // spinner.hide();
                    $(document).scrollTop(0);
                    that.historyManage(url, param, data);
                    $RT.html(data);
                    GML.Raider.hunt();
                    /*
                    var navItems = $('.navItem', theater);
                    for(var i=0; i<navItems.length; i++){
                        var $this = $(navItems[i]);
                        that.packNav($this);
                    }
                    */
                    $RT.css('minHeight', '');
                    GML.ScrollView.pipe();
                    // GML.HTML5Shim.pipe();
                }
            })
        );
    }

    P.mapping = function(url){
        var that = P
            , map = that.map;
        for(var i=0; i<map.length; i++){
            var item = map[i];
            if(item[0].indexOf(url) > -1){
                if(url === '/gmvo/message/companyInquiry.gm' || url === '/gmvo/buyermessage/inbox.gm'){
                    if(!item[1].closest('#siteMap').length){
                        that.guided(item[1]);
                        break;
                    }
                }else if(url === '/gmvo/buyinglead/loadMyBuyingLeadList.gm'){
                    if(!item[1].closest('.stage').length){
                        that.guided(item[1]);
                        break;
                    }
                }else if(url === '/gmvo/buyinglead/loadBuyingLeadList.gm'){
                    if(!item[1].closest('.stage').length){
                        that.guided(item[1]);
                        break;
                    }
                }else if(url === '/gmvo/buyerbuyinglead/loadBuyerBuyingLeadPage.gm?label=approved' || url === '/gmvo/mygm/sourcingevent/se/enterSrcEventList.gm'){
                    if(!item[1].closest('.stage').length){
                        that.guided(item[1]);
                        break;
                    }
                }else{
                    that.guided(item[1]);
                    break;
                }
            }
        }
    }

    P.renderNav = function(){
        var that = P
            , $siteNav = $('.site-nav.nav-overall')
            , preNavItem = $('.tit-unfold', $siteNav)
            ;
        that.preNavItem = preNavItem;
        that.preNavItemStage = preNavItem.siblings('.stage');
        that.preCur = $('.cur', $siteNav);

        $('.level-top', $('#container > .extra')).click(function(e){
            that.manageMenu($(this), true);
            e.preventDefault();
        });
        that.mapping(window.location.pathname);
    }

    P.guided = function(element){
        var that = P
            , $this = element
            ;

        that.manageMenu($this.closest('.stage').siblings('.level-top'));
        that.preCur.removeClass('cur');
        $this.addClass('cur');
        that.preCur = $this;
    }

    P.manageMenu = function(element, click){
        var that = P
            , $this = element
            , stage, preNavItem
            ;

        if(!$this.length){
            $this = $('#siteMap li:first > a');
        }
        if($this.hasClass('tit-retracting')){
            that.preNavItem.removeClass('tit-unfold').addClass('tit-retracting');
            that.preNavItemStage.slideToggle(300);
            $this.removeClass('tit-retracting');
            $this.addClass('tit-unfold');
            stage = $this.siblings('.stage');
            stage.slideToggle(300);
            that.preNavItem = $this;
            that.preNavItemStage = stage;
        }else if(click){
            $this.removeClass('tit-unfold');
            $this.addClass('tit-retracting');
            stage = $this.siblings('.stage');
            stage.slideToggle(300);
            that.preNavItem = $('');
            that.preNavItemStage = $('');
        }
    }
    
    P.formDig = function(element){
        var $form = element;

        if(!$form.valid()){
            return;
        }
        var action = $.trim($form.attr('action'))
            // , params = $form.serialize().replace(/\+/g,' ').split('&')
            , that = P
            , data = {}
            , $RT = GML.RT
            , param
            ;

        /*
        for(var i=0; i<params.length; i++){
            var item = params[i].split('=')
                , key = item[0]
                , value = item[1]
                ;
            data[key] = decodeURIComponent(value);
        }
        */
        param = $form.serialize();
        if(param){
            param += '&pipe=ajax';
        }
        that.xhrQ(
            $.ajax({
                type: 'POST',
                url: action,
                data: param,
                beforeSend: function(){
                    GML.Spinner($RT);
                },
                error: function(jqXHR){
                    if(jqXHR.status !== 0){
                        $RT.html('Sorry, I\'m afraid the page you requested doesn\'t exist.');
                    }
                    GML.Spinner($RT);
                },
                success: function(data){
                    $RT.unbind('click');
                    $(document).scrollTop(0);
                    $RT.html(data);
                    GML.Spinner($RT);
                    GML.Raider.hunt();
                    GML.ScrollView.pipe();
                    // GML.HTML5Shim.pipe();
                }
            })
        );
    }

    P.historyManage = function(u, p, d){
        var param = p
            , param, storage, url
            , that = P
            , ua = navigator.userAgent
            , re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})")
            , rv
            ;

        if(re.exec(ua) != null){
            rv = parseFloat(RegExp.$1);
        }
        if(rv){
            return false;
        }
        if(u){
            if(u.indexOf('://') < 0){
                url = location.protocol + '//' + location.host + u;
            }else{
                url = u;
            }
        }else{
            url = location.href; // location.protocol + '//' + location.host + location.pathname + location.search;
        }
        if(param){
            if(param['pipe']){
                delete param['pipe'];
            }
            param = $.param(param);
            if(param){
                if(url.indexOf('?') < 0){
                    url += '?' + param;
                }else{
                    url += '&' + param;
                }
            }
        }
        if(!rv){
            if(!history.state || history.state.url !== url){
                d = d ? d : GML.RT.html();
                storage = {
                    'cont': d,
                    'url': url
                }
                history.pushState(storage, url, url);
                that.init = false;
            }
        }else{
        /*
            var baseURL = '/r-url';
            url = url.substr(7);
            if(url){
                window.location.hash = '!/' + url;
            }else{
                window.location.hash = '!/home';
            }
            if(rv < 8){
                m.timer++;
                $('#ifm').attr('src', 'http://192.168.88.207/test/history.php?|index=' + m.timer + '#' + url);
            }
            */
        }
    }

    P.swapNav = function(t){
        var that = P
            , target = t
            , $nav = $("")
            , d = -1 * that.curNav.overallW
            , name
            ;

        if(that.curNav.name !== target){
            switch(target){
                case 'MsgMvo':
                    $nav = that.MsgMvoNav;
                    name = 'MsgMvo';
                    break;
                case 'BLMvo':
                    $nav = that.BLMvoNav;
                    name = 'BLMvo';
                    break;
                case 'MsgBvo':
                    $nav = that.MsgBvoNav;
                    name = 'MsgBvo';
                    break;
                case 'BLBvo':
                    $nav = that.BLBvoNav;
                    name = 'BLBvo';
                    break;
                case 'SEventBvo':
                    $nav = that.SEventBvo;
                    name = 'SEventBvo';
                    break;
                case 'overall':
                default:
                    name = 'overall';
                    d = 0;
                    break;
            }
            $nav.show();
            // return false;
            that.overallNav.animate({
                'marginLeft': d
            }, 600, function(){
                that.curNav.item.hide();
                that.curNav.name = name;
                that.curNav.item = $nav;
            });
        }
    }

    P.reHide = function(e){
        var $this = e;
        $this.hide();
        $this.removeClass('hidden');
    }

    P.xhrQ = function(x){
        P.xhr.push(x);
    }

    P.init();
    return P;

})();


